package com.design.movieticket.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.design.movieticket.dto.MovieDto;
import com.design.movieticket.entity.Movie;
import com.design.movieticket.entity.User;
import com.design.movieticket.mapper.MovieMapper;
import com.design.movieticket.service.MovieService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MovieServiceImpl extends ServiceImpl<MovieMapper, Movie> implements MovieService{

    @Resource
    private MovieMapper movieMapper;

    /** 分页查询 */
    @Override
    public LambdaQueryWrapper buildQuery(Movie movie) {
        LambdaQueryWrapper lambdaQueryWrapper;
        if (movie.getPlayStatus() == 88){
            lambdaQueryWrapper = Wrappers.lambdaQuery(Movie.class)
                    .eq(StringUtils.isNotBlank(movie.getMovieName()),Movie::getMovieName,movie.getMovieName())
                    .in(Movie::getPlayStatus,0,1,2);
        }
        else{
            lambdaQueryWrapper = Wrappers.lambdaQuery(Movie.class)
                    .eq(StringUtils.isNotBlank(movie.getMovieName()),Movie::getMovieName,movie.getMovieName())
                    .in(Movie::getPlayStatus,movie.getPlayStatus());
        }
        return lambdaQueryWrapper;
    }

    /** 分页相关 */
    @Override
    public <E extends IPage<Movie>> E page(E page, Wrapper<Movie> queryWrapper) {
        return super.page(page, queryWrapper);
    }

    /** 新增或更新电影数据 */
    @Override
    public void addOrUpdateMovieInfo(Movie movie) {
        super.saveOrUpdate(movie);
    }

    /** 获取电影信息详情 */
    @Override
    public Movie getMovieDetail(long id) {
        return super.getById(id);
    }

    /** 删除电影信息 */
    @Override
    public void delMovieById(long id) {
        super.removeById(id);
    }


    @Override
    public List<MovieDto> wxGetMovieListForHot() {
        return movieMapper.wxGetMovieListForHot();
    }

    @Override
    public List<MovieDto> wxGetMovieListForFuture() {
        return movieMapper.wxGetMovieListForFuture();
    }

    @Override
    public List<MovieDto> wxGetMovieListByCinemaId(Long id) {
        return movieMapper.wxGetMovieListByCinemaId(id);
    }
}
